home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 451-475 / disk_457 / cmanual / acm4.lzh / Input / Keyboard.c < prev    next >
C/C++ Source or Header  |  1990-11-24  |  1KB  |  49 lines

  1. /* Keyboard()                                                          */
  2. /* Keyboard() is a handy, easy and fast but naughty function that hits */
  3. /* the hardware of the Amiga. It checks the keyboard, and returns the  */
  4. /* Raw Key Code. (See chapter (C) SYSTEM DEFAULT CONSOLE KEY MAPPING   */
  5. /* for the full list of Raw Key Codes.)                                */
  6. /*                                                                     */
  7. /* Synopsis: value = Keyboard();                                       */
  8. /* value:    (UBYTE) Raw Key Code. For example: If the user hits key   */
  9. /*           "N", the function returns 36 (hexadecimal). When the user */
  10. /*           releases the key, B6 is returned.                         */
  11.  
  12.  
  13. #include <exec/types.h>
  14. #include <hardware/cia.h>
  15.  
  16.  
  17. #define CIAA 0xBFE001
  18.  
  19. struct CIA *cia = (struct CIA *) CIAA;
  20.  
  21.  
  22. void main();
  23. UBYTE Keyboard();
  24.  
  25.  
  26. void main()
  27. {
  28.   int loop;
  29.   
  30.   for( loop = 0; loop < 100; loop++ )
  31.     printf("Code: %2x\n", Keyboard() );
  32. }
  33.  
  34.  
  35. UBYTE Keyboard()
  36. {
  37.   UBYTE code;
  38.  
  39.   /* Get a copy of the SDR value and invert it: */
  40.   code = cia->ciasdr ^ 0xFF;
  41.   
  42.   /* Shift all bits one step to the right, and put the bit that is */
  43.   /* pushed out last: 76543210 -> 07654321                         */
  44.   code = code & 0x01 ? (code>>1)+0x80 : code>>1;
  45.  
  46.   /* Return the Raw Key Code Value: */
  47.   return( code );
  48. }
  49.